package org.apache.dubbo.demo.provider;

import org.apache.dubbo.rpc.RpcContext;
import org.apache.dubbo.sample.tri.GreeterReply;
import org.apache.dubbo.sample.tri.GreeterRequest;
import org.apache.dubbo.sample.tri.PbGreeter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.CompletableFuture;

public class PbGreeterImpl implements PbGreeter {

    private static final Logger logger = LoggerFactory.getLogger(PbGreeterImpl.class);

    @Override
    public GreeterReply greet(GreeterRequest request) {

        logger.info("Hello " + request.getName() + ", request from consumer: " + RpcContext.getContext().getRemoteAddress());
        return GreeterReply.newBuilder()
                .setMessage("Hello " + request.getName() + ", response from provider: "
                        + RpcContext.getContext().getLocalAddress() + " port: " + RpcContext.getContext().getRemotePort())
                .build();
    }

    @Override
    public CompletableFuture<GreeterReply> greetAsync(GreeterRequest request) {
        return CompletableFuture.completedFuture(greet(request));
    }

    @Override
    public GreeterReply greetWithAttachment(GreeterRequest request) {
        return null;
    }

    @Override
    public CompletableFuture<GreeterReply> greetWithAttachmentAsync(GreeterRequest request) {
        return null;
    }

    @Override
    public GreeterReply greetException(GreeterRequest request) {
        return null;
    }

    @Override
    public CompletableFuture<GreeterReply> greetExceptionAsync(GreeterRequest request) {
        return null;
    }

    @Override
    public GreeterReply greetStream(GreeterRequest request) {
        return null;
    }

    @Override
    public CompletableFuture<GreeterReply> greetStreamAsync(GreeterRequest request) {
        return null;
    }

    @Override
    public GreeterReply greetServerStream(GreeterRequest request) {
        return null;
    }

    @Override
    public CompletableFuture<GreeterReply> greetServerStreamAsync(GreeterRequest request) {
        return null;
    }
}
